#include <iostream>
#include <vector>
#include <string>
#include <algorithm>

constexpr unsigned long empty=-1;
constexpr bool debugMode=false;

unsigned long wayUpRecrusive(
    const std::vector<std::vector<unsigned long>> &board,
    const int i, const int j,std::vector<std::vector<unsigned long>> &record){
 
    if(i>=board.size()||j>=board[i].size()){
        std::cout<<"holy shit"<<std::endl;
        throw std::runtime_error("asshole");
    }

    // 记忆化
    if(record[i][j]!=empty){
        return record[i][j];
    }

    if(i+1>=board.size()){
        record[i][j]=board[i][j];
        return record[i][j];
    }

    record[i][j]=std::max(
        wayUpRecrusive(board,i+1,j,record),
        wayUpRecrusive(board,i+1,j+1,record)
    )+board[i][j];

    return record[i][j];
}

template<typename elem>
void showAll(const std::vector<std::vector<elem>> &board){
    for(int i=0;i<board.size();i++){
        for(int j=0;j<board[i].size();j++){
            std::cout<<board[i][j]<<' ';
        }
        std::cout<<std::endl;
    }
}

unsigned long maxPathAPI(
    const std::vector<std::vector<unsigned long>> &board){
    // 初始化->empty
    std::vector<std::vector<unsigned long>> record(board.size());
    for(int i=0;i<board.size();i++){
        record[i]=std::vector<unsigned long>(i+1,empty);
    }

    const unsigned long tmp=wayUpRecrusive(board,0,0,record);

    if(debugMode){
        showAll<unsigned long>(record);
    }

    return tmp;
}

int main(){
    int r;
    std::cin>>r;

    std::vector<std::vector<unsigned long>> board(r);
    for(int i=0;i<board.size();i++){
        board[i]=std::vector<unsigned long>(i+1);
        for(int j=0;j<=i;j++){
            scanf("%ul",&board[i][j]);
        }
    }

    // std::cout<<"读取结果\n";
    // showAll(board);

    std::cout<<maxPathAPI(board);

    // std::cout<<"hello world"<<std::endl;
    // 道歉会不会
    return 0;
}